/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-04-28
 * Time: 15:43
 */
//把这个类设置为单例
class Singleton {
    private static Singleton instance = new Singleton();

    //获取到实例的方法
    public static Singleton getInstance() {
        return instance;
    }

    //禁止new 将构造方法设置为private
    private Singleton() {

    };
}



public class ThreadDemo14 {
    public static void main(String[] args) {
        Singleton s1 =  Singleton.getInstance();
        //此时s1和s2是同一个对象
        //Singleton s2 =  Singleton.getInstance();
        //此时不能再进行new了,外部无法创建实例
        //Singleton s3 = new Singleton();
    }
}
